#include  <ctype.h>
#include  <stdlib.h>

#include "def.h"
#include "option.h"
#include "2440addr.h"     
#include "2440lib.h"
#include "2440slib.h"     
#include "mmu.h" 
#include "timer_raw.h"

#include "dm9000.h"
#include "raw_api.h"




//RAW_U16 raw_os_start();

#define TASK1_STACK_SIZE   2048

#define  MAIN_TASK_STK_SIZE       2048
#define  SIMULATION_TASK_STK_SIZE       2048
PORT_STACK test_uip_stack[TASK1_STACK_SIZE];

PORT_STACK main_stack[ MAIN_TASK_STK_SIZE];
PORT_STACK simulation_task_stack[ SIMULATION_TASK_STK_SIZE];
PORT_STACK tcp_ip_stack[ SIMULATION_TASK_STK_SIZE];
PORT_STACK ping_stack[ SIMULATION_TASK_STK_SIZE];
PORT_STACK watch_stack[ SIMULATION_TASK_STK_SIZE];

RAW_TASK_OBJ 		main_task_obj;
RAW_TASK_OBJ 		simulation_net_driver_obj;
RAW_TASK_OBJ 		tcp_ip_obj;
RAW_TASK_OBJ 		ping_obj;
RAW_TASK_OBJ 		watch_obj;
RAW_TASK_OBJ 		test_uip_obj;


void tcp_thread(void *arg); 


void tcp_ip_thread(void *arg) ;


void CPU_IntDis(void);
void CPU_IntEn(void);

void first_task(void * pParam) 
{


	//PrintfDM9000Reg();

	while(1)
	{
//	Uart_Printf("in fisrt_task \n");
	Dm9000_Test();
	raw_sleep(1800);
	}	
	
}


void main_task(void * pParam) 
{	
	 
	 
   Uart_Printf("in main_task \n");	 

	raw_task_create(&ping_obj, (RAW_U8  *)"tcp_ip_obj", 0,
	                         20, 0,  ping_stack, 
	                          SIMULATION_TASK_STK_SIZE , tcp_thread, 1); 

	#if 0
	raw_task_create(&test_uip_obj, (RAW_U8  *)"task1", 0,
	                         30, 0,  test_uip_stack, 
	                         TASK1_STACK_SIZE ,  first_task, 1); 

	#endif
	

	raw_task_delete(&main_task_obj);
	
}



extern RAW_U8 test_started;


void uip_test()
{

	if (test_started) {

		return;

	}

	test_started = 1;
	
	raw_task_create(&main_task_obj, (RAW_U8  *)"task1", 0,
	                         1, 0,  main_stack, 
	                         MAIN_TASK_STK_SIZE , main_task, 1); 	
}

